#include "AsioThreadPool.h"



AsioThreadPool::~AsioThreadPool()
{
    //Stop();
}
boost::asio::io_context& AsioThreadPool::GetIOService()
{
    return io_context_;
}
AsioThreadPool::AsioThreadPool(int thread_num)
{
    work_ = std::make_unique<boost::asio::io_context::work>(io_context_);
    threads_.reserve(thread_num);
    for(int i=0;i<thread_num;i++)
    {
        threads_.emplace_back([this](){
            io_context_.run();
        });
    }
}
void AsioThreadPool::Stop()
{
    work_.reset();
    io_context_.stop();
    for(auto& thread:threads_)
    {
        thread.join();
    }
}
